import React,{lazy,Suspense,startTransition} from 'react';


    const OtherComponent = lazy(() => import('./OtherComponent'));
    const OtherComponent2 = lazy(() => import('./OtherComponent2'));

const Lzay = () => {
    let [show,setShow] = React.useState(true);
    return (
        <div>
            <h1>懒加载组件 React.lazy 以及 React.suspence 的使用</h1>
            <button onClick={() => setShow(!show)}>切换组件</button>
            <Suspense fallback={<div>Loading...</div>}>
                {show ? <OtherComponent /> : <OtherComponent2 />}
            </Suspense>
        </div>
    );
};

export default Lzay;